package org.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.Collections;

@Configuration
@EnableOpenApi
public class SwaggerConfig {

    /**
     * swagger配置
     */
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.example.rest")) //扫描包路径
                .paths(PathSelectors.regex("^(?!.*\\/error).*"))
                .build()
                .apiInfo(apiInfo())
                .enable(true); // 是否启用，我们可以使用这个属性关闭生产环境的swagger文档
    }

    // 文档的一些描述信息
    private ApiInfo apiInfo() {
        return new ApiInfo(
                "接口文档", "", "1.0", "",
                new Contact("xxxx", "", "123@163.com"),
                "strongmore", "", Collections.emptyList());
    }
}